/**
 * Created by 李柏霖
 * 2020/10/27 19:54
 */

package cn.lbl.face.wm;

import java.util.ArrayList;

public class Solution {
    /**
     * 查询手机号的运营商，手机号格式合法则返回运营商名称，不合法则返回"Illegal format"
     * @param phone string字符串 手机号码
     * @return string字符串
     */
    public static String queryPhoneOperators (String phone) {
        // write code here
        ArrayList<String> china_Telecom = new ArrayList<>();
        china_Telecom.add("133");china_Telecom.add("153");china_Telecom.add("180");
        china_Telecom.add("181");china_Telecom.add("189");
        ArrayList<String> china_Unicom = new ArrayList<>();
        china_Unicom.add("130");china_Unicom.add("131");china_Unicom.add("155");
        china_Unicom.add("185");china_Unicom.add("186");
        ArrayList<String> china_Mobile = new ArrayList<>();
        china_Mobile.add("135");china_Mobile.add("136");china_Mobile.add("150");
        china_Mobile.add("182");china_Mobile.add("188");
        ArrayList<String> list = new ArrayList<>();
        list.add("0");list.add("1");list.add("2");list.add("3");list.add("4");
        list.add("5");list.add("6");list.add("7");list.add("8");list.add("9");
        if (phone.length()==11) {
            for (int i = 0; i < 11; i++) {
                if (!list.contains(String.valueOf(phone.charAt(i)))) {
                    return "Illegal format";
                }
            }
            String substring = phone.substring(0, 3);
            if (china_Telecom.contains(substring)) {
                return "China Telecom";
            }else if (china_Unicom.contains(substring)) {
                return "China Unicom";
            }else if (china_Mobile.contains(substring)) {
                return "China Mobile";
            }
        }
            return "Illegal format";
    }

    public static void main(String[] args) {
//        System.out.println(queryPhoneOperators("1556933639A"));
        System.out.println(queryPhoneOperators("18066568866"));
    }
}
